package com.bobo.util;

import com.bobo.service.CheckTokenService;
import org.apache.commons.fileupload.RequestContext;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class ForRepearCommitAop {
    @Autowired
    CheckTokenService checkTokenService;
    //提交前进行校验
    @Before(value="@annotation(com.bobo.util.ForRepeatCommit)")
    public void valid(){

        ServletRequestAttributes requestAttributes=  (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        //用户请求sessionid和请求地址当做唯一的key
        String token = requestAttributes.getRequest().getParameter("token");
        System.out.println(token);
        String key=requestAttributes.getSessionId()+"-"+request.getServletPath();
        //调用校验key
        checkTokenService.checkSessionIdAndUrl(token);
    }

}
